import request from '@/utils/request'

// 查询字典数据列表
export function listData(query) {
  return request({
    url: '/system/dict/data/list',
    method: 'get',
    params: query
  })
}

// 查询字典数据详细
export function getData(dictCode) {
  return request({
    url: '/system/dict/data/' + dictCode,
    method: 'get'
  })
}

// 根据字典类型查询字典数据信息||dictType=='sys_device_type'
export function getDicts(dictType) {
  let requestUrl='/system/dict/data/type/' + dictType
  if(localStorage.getItem('hospital')){
    let hospObj=JSON.parse(localStorage.getItem('hospital'))
    let hospitalId=hospObj.deptId
    if(hospitalId&&hospObj.ancestors.split(',').length != 1){
      if(dictType=='sys_picking_location'||dictType=='sys_treatment_reaction'
      ||dictType=='sys_patient_reason'||dictType=='sys_face_part'||dictType=='sys_treatment_parameter'){
        requestUrl='/system/dict/data/type/' + dictType+'/'+hospitalId
      }
    }
  }
 
  return request({
    url: requestUrl,
    method: 'get'
  })
  

}

// 新增字典数据
export function addData(data) {
  return request({
    url: '/system/dict/data',
    method: 'post',
    data: data
  })
}

// 修改字典数据
export function updateData(data) {
  return request({
    url: '/system/dict/data',
    method: 'put',
    data: data
  })
}

// 删除字典数据
export function delData(dictCode) {
  return request({
    url: '/system/dict/data/' + dictCode,
    method: 'delete'
  })
}

// 获取字典单项字典键值最大值
export function maxValue(dictType) {
  return request({
    url: '/system/dict/data/maxValue/'+dictType,
    method: 'get'
  })
}
